package top.kiterunner.learning.container_test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * AdorynZhao in Tencent-UESTC.
 * Source Code Created on 2017/7/23.
 */
public class TreeMapTest {

    public static class Key implements Comparable<Key>{

        public int key_value;

        public Key() {
            key_value = 0;
        }

        public Key(int key_value) {
            this.key_value = key_value;
        }

        @Override
        public int compareTo(Key o) {
            if (key_value > o.key_value)
                return 1;
            else if (key_value < o.key_value)
                return -1;
            return 0;
        }
    }

    public static Map<Key, String> testMap = new TreeMap<>();

    public static void initTreeMap() {
        testMap.put(new Key(10), "Hello");
        testMap.put(new Key(88), "Jack");
        testMap.put(new Key(22), "Hill");
        testMap.put(new Key(11), "Stack");
        testMap.put(new Key(45), "Strip");
        testMap.put(new Key(15), "Hole");
    }

    public static void walkThroughMap() {
        Iterator<Map.Entry<Key, String>> iter = testMap.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<Key, String> item = iter.next();
            System.out.println("Key = " + item.getKey().key_value + " Value = " + item.getValue());
        }
    }

    public static void main(String[] args) {
        initTreeMap();
        walkThroughMap();

        ExecutorService service = Executors.newWorkStealingPool();

        System.out.println("Val = " + (1 << 16));
        int hash = 65536;
        System.out.println("Val = " + (hash >>> 16) + " hash = " + hash);
    }


}
